package com.zhouyu;

import com.zhouyu.service.UserInterface;
import com.zhouyu.service.UserService;
import org.springframework.aop.MethodBeforeAdvice;
import org.springframework.aop.framework.ProxyFactory;

import java.lang.reflect.Method;

public class ProxyFactoryDemo {
	public static void main(String[] args) {
		UserService target = new UserService();
		ProxyFactory proxyFactory = new ProxyFactory();
		proxyFactory.setTarget(target);
		// 如果不指定接口默认使用 Cglib
		//proxyFactory.setInterfaces(UserInterface.class);
		proxyFactory.addAdvice(new MethodBeforeAdvice() {
			@Override
			public void before(Method method, Object[] args, Object target) throws Throwable {
				System.out.println("before...");
			}
		});

		UserInterface proxy = (UserInterface) proxyFactory.getProxy();
		proxy.test();
	}
}
